package com.tanhua.server.controller;

import com.tanhua.domain.UserInfo;
import com.tanhua.server.service.MessageService;
import com.tanhua.vo.HuanXinUserVo;
import com.tanhua.vo.PageResult;
import com.tanhua.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {
    @Autowired
    private MessageService messageService;

    /**
     * 通过环信id查询用户详情
     * @param huanxinId
     * @return
     */
    @GetMapping("/userInfo")
    public ResponseEntity getHXUserInfo(String huanxinId){
        UserInfoVo vo = messageService.getHXUserInfo(huanxinId);
        return ResponseEntity.ok(vo);
    }

    /**
     * 联系人添加
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Long friendId = Long.valueOf(map.get("userId").toString());
        messageService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    /**
     * 获取联系人列表
     * @param pagesize
     *
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity getContactsList(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer pagesize,
                                            String keyword){
        PageResult pageResult = messageService.getContactsList(page,pagesize,keyword);
        return ResponseEntity.ok(pageResult);
    }
}
